home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-07 | 3.8 KB | 130 lines | [TEXT/MPS ] |
- (*
- CTBNewTerminal [tool] -- Make a new terminal tool. If one is open, dispose of it. The tool
- parameter is the initial tool name to use.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w CTBNewTerminal.p
- link -m ENTRYPOINT -o HyperCommands -rt XCMD=2759 -sn Main=CTBNewTerminal ∂
- CTBNewTerminal.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
-
- © Copyright 1990 by Apple Computer, Inc.
-
- Initial coding 2/90 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S CTBNewTerminal } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, Windows, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf,
- HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure CTBNewTerminal(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- CTBNewTerminal(paramPtr);
- end;
-
- procedure CTBNewTerminal(paramPtr: XCmdPtr);
-
- {$I CTBUtil.inc}
-
- var i, j: integer;
- r: Rect;
- toolName: Str255;
- procID: integer;
- tHand: TermHandle;
- gWind: WindowPtr;
- h: Handle;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(CTBNewTerminal);
- end;
-
- begin
- { Check for a valid parameter count. }
- if paramPtr^.paramCount > 1 then Fail('Invalid parameter count');
-
- { Ensure we're loaded and ready. }
- CTBReady;
-
- { If there's already a terminal open, close it. }
- if Globals^^.termHand <> nil then
- begin
- { Dispose of the terminal emulator. }
- gWind := Globals^^.termHand^^.owner;
- h := Handle(TMGetUserData(Globals^^.termHand));
- TMDispose(Globals^^.termHand);
- { Get rid of our invisible window. }
- CloseWindow(gWind);
- DisposHandle(h);
- { Remove it from the tool list. }
- j := 1;
- for i := 1 to Globals^^.allToolsSize do
- if Globals^^.allTools[i].tHand <> Globals^^.termHand then
- begin
- Globals^^.allTools[j] := Globals^^.allTools[i];
- j := j+1;
- end;
- Globals^^.allToolsSize := Globals^^.allToolsSize-1;
- SetHandleSize(Handle(Globals),sizeof(OurGlobalType)-sizeof(ToolArray)+
- Globals^^.allToolsSize*sizeof(OneToolType));
- Globals^^.termHand := nil;
- end;
-
- { Find the proc ID. }
- if ParmPresent(1) then GetStrParm(1,toolName)
- else toolName := 'TTY Tool';
- { Look up the requested proc ID. }
- procID := TMGetProcID(toolName);
- if procID = -1 then
- begin
- { If it wasn't there, then just get the first terminal tool that is there. }
- if CRMGetIndToolName(ClassTM,1,toolName) <> noErr then procID := -1
- else procID := TMGetProcID(toolName);
- { If there are no terminal tools, fail. }
- if procID = -1 then Fail('Cannot find a default tool');
- end;
-
- { Allocate a window for use by the tool (even though we'll never make it visible). }
- r.top := 0; r.left := 0; r.bottom := 100; r.right := 100;
- { Allocate storage for the WindowRecord. }
- h := NewHandle(sizeof(WindowRecord));
- if h = nil then Fail('Cannot allocate memory');
- MoveHHi(h);
- HLock(h);
- gWind := NewWindow(StripAddress(h^),r,'x',false,noGrowDocProc,nil,false,0);
- if gWind = nil then Fail('Could not create buffer');
- { Create the new connection handle. }
- tHand := TMNew(r,r,tmInvisible+tmNoMenus,procID,gWind,nil,nil,nil,nil,nil,0,ord4(h));
- Globals^^.termHand := tHand;
- if Globals^^.termHand = nil then
- begin
- CloseWindow(gWind);
- DisposHandle(h);
- Fail('Could not create new terminal record');
- end;
- { Save it. }
- Globals^^.allToolsSize := Globals^^.allToolsSize+1;
- { And add it to the outstanding tool list. }
- SetHandleSize(Handle(Globals),sizeof(OurGlobalType)-sizeof(ToolArray)+
- Globals^^.allToolsSize*sizeof(OneToolType));
- Globals^^.allTools[Globals^^.allToolsSize].tType := terminalTool;
- Globals^^.allTools[Globals^^.allToolsSize].tHand := Globals^^.termHand;
- end;
-
- end.
-